<include file="public@header" />
<link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/css/index.css" />
<script src="__TMPL__/public/assets/js/distpicker.min.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
	select[name='province'],
	select[name='city'],
	select[name='area']{
		margin-bottom: 5px;
	}
	.inner {
		white-space: nowrap;
	}
	.inner>div{
		display: inline-block;
	}
</style>
</head>

<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a>{:lang('USER_INDEXADMIN_INDEX')}</a></li>
		</ul>
		<form class="well form-inline margin-top-20" method="post" action="{:url('user/adminIndex/index')}">

			<div class="inner">
				地区:
				<div data-toggle="distpicker" style="white-space: nowrap;">
					<select class="form-control" data-province="{:input('request.province')}" name="province"></select>
					<select class="form-control" data-city="{:input('request.city')}" name="city"></select>
					<select class="form-control" data-district="{:input('request.area')}" name="area"></select>
				</div>
              状态:
				<select class="form-control" name="status" style="width: 150px;">
					<option value='' selected>全部</option>
					<option value='待处理' <if condition="$status eq '待处理'">selected</if>>待处理</option>
					<option value='约访' <if condition="$status eq '约访'">selected</if>>约访</option>
					<option value='办案中' <if condition="$status eq '办案中'">selected</if>>办案中</option>
					<option value='成交' <if condition="$status eq '成交'">selected</if>>成交</option>
					<option value='完成' <if condition="$status eq '完成'">selected</if>>完成</option>
					<option value='公海' <if condition="$status eq '公海'">selected</if>>公海</option>
				</select>
			</div>
			跟进人员:
			<input class="form-control" type="text" name="name" style="width: 200px;" value="{:input('request.name')}"
			 placeholder="请输入正确的跟进人员姓名">
			手机号:
			<input class="form-control" type="text" name="phone" style="width: 200px;" value="{:input('request.phone')}"
			 placeholder="请输入用户手机号">
			<input type="submit" class="btn btn-primary" value="搜索" />
			<a class="btn btn-danger" href="{:url('user/adminIndex/index')}">清空</a>
		</form>
		<button class="btn btn-default new_btn" onclick="show_name()">添加新用户</button>
		<form method="post" class="js-ajax-form">
			<table class="table table-hover table-bordered">
				<thead>
					<tr>
						<th>UID</th>
						<th>手机号</th>
                      	<th>姓名</th>
						<th>地区</th>
						<th>法律报告</th>
						<th>订单</th>
						<th>跟进人员</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="list" item="vo">
						<tr>
							<td><a href="{:url('user/adminIndex/user_details',array('user_id'=>$vo['id']))}">{$vo.id}</a></td>
							<td>{$vo.phone}</td>
                          	<td>{$vo.name}</td>
							<td>{$vo.province}{$vo.city}{$vo.area}</td>
							<td>
								<foreach name="vo['report']" item="v">
									{$v.report_no}<br />
								</foreach>
							</td>
							<td>
								<foreach name="vo['order']" item="v">
									{$v.order_type}<br />
								</foreach>
							</td>
							<td>
								<if condition="$vo.get_about neq null">
									约访人:{$vo.get_about['user_login']}<br />
								</if>
								<if condition="$vo.get_lawyer neq null">
									律师:{$vo.get_lawyer['user_login']}
								</if>
							</td>
							<td>{$vo.status}</td>
							<td class="button_box">
								<if condition="$vo.status eq '待处理'">
									<span class="btn btn-xs btn-primary" onclick="show_raload('{$vo.id}')">指派人员</span>
									<elseif condition="$vo.status eq '待约访'" />
									<span class="btn btn-xs btn-primary" onclick="show_record('{$vo.id}')">约访</span>
									<elseif condition="$vo.status eq '公海'" />
									<span class="btn btn-xs btn-primary" onclick="pick({$vo.id})">捡起</span>
									<elseif condition="($vo.status eq '成交') OR ($vo.status eq '办案中') OR ($vo.status eq '案件完结')" />
									<span class="btn btn-xs btn-primary" onclick="show_report('{$vo.id}')">添加报告</span>
									<span class="btn btn-xs btn-primary" onclick="show_order('{$vo.id},{$vo.get_about.id}')">添加订单</span>
									<elseif condition="($vo.status eq '拖欠尾款') OR ($vo.status eq '无尾款') OR ($vo.status eq '完成') OR ($vo.status eq '退费') OR ($vo.status eq '坏账')" />
									<span class="btn btn-xs btn-primary" onclick="show_report('{$vo.id}')">添加报告</span>
									<span class="btn btn-xs btn-primary" onclick="show_order('{$vo.id},{$vo.get_about.id}')">添加订单</span>
									<span class="btn btn-xs btn-primary" onclick="show_raload('{$vo.id}')">重新指派</span>
									<else />
									<span class="btn btn-xs btn-primary" onclick="show_report('{$vo.id}')">添加报告</span>
									<span class="btn btn-xs btn-primary" onclick="show_order('{$vo.id},{$vo.get_about.id}')">添加订单</span>
									<span class="btn btn-xs btn-primary" onclick="show_record('{$vo.id}')">约访</span>
									<span class="btn btn-xs btn-primary" onclick="show_discard('{$vo.id}')">丢入公海</span>
									<span class="btn btn-xs btn-primary" onclick="show_raload('{$vo.id}')">重新指派</span>
								</if>
							</td>
						</tr>
					</foreach>
				</tbody>
			</table>
			<div class="pagination">{$page}</div>
		</form>
	</div>
	<!-- 弹窗 -->
	<div class="tc_bg">
		<!-- 添加新用户 -->
		<div class="tc_box user_box">
			<p class="tc_title">添加新用户</p>
			<div class="tc_txt_box">
				<p class="tc_txt">手机号：</p>
				<input type="text" style="width: 75%;" name="phone" placeholder="请输入手机号码" maxlength="11" oninput="value=value.replace(/[^\d]/g,'')">
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="phone()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>
		<!-- 添加订单 -->
		<div class="tc_box order_box">
			<p class="tc_title">添加订单</p>
			<div class="tc_txt_box">
				<p class="tc_txt">订单类型选择：</p>
				<select class="dd_list" name="order" style="width: 60%;">
					<option value="劳动纠纷服务包" selected="selected">劳动纠纷服务包</option>
					<option value="劳动纠纷服务包">劳动纠纷服务包</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">首支付款：</p>
				<div style="width: 60%;">
					<input type="text" style="width: 70%;" name="money" placeholder="请输入" oninput="value=value.replace(/[^\d]/g,'')">
					<span class="tc_txt">元</span>
				</div>
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="order()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>
		<!-- 丢入公海 -->
		<div class="tc_box discard_box">
			<p class="tc_title">丢入公海</p>
			<p class="tc_txt">原因：</p>
			<div class="tc_txt_box">
				<input type="text" style="width: 100%;" name="why" placeholder="请输入">
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="discard()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>
		<!-- 重新指派 -->
		<div class="tc_box reload_box">
			<p class="tc_title">指派约访人</p>
			<div class="tc_txt_box">
				<p class="tc_txt">约访人：</p>
				<input type="text" name="people" style="width: 75%;" placeholder="请输入">
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="raload()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>
		<!-- 约访记录 -->
		<div class="tc_box record_box">
			<p class="tc_title">约访记录</p>
			<div class="tc_txt_box">
				<p class="tc_txt">约访形式：</p>
				<select class="dd_list" name="record_list" style="width: 60%;">
					<option value="请选择" selected="selected">--请选择--</option>
					<option value="电话">电话</option>
					<option value="微信">微信</option>
					<option value="面谈">面谈</option>
				</select>
			</div>
			<p class="tc_txt">约访时间：</p>
			<div class="tc_txt_box">
				<input type="text" class="form-control js-bootstrap-datetime" name="record_time" placeholder="请选择时间" style="width: 100%; text-indent: .5em;" />
			</div>
			<p class="tc_txt">约访记录：</p>
			<div class="tc_txt_box">
				<input type="text" name="record_txt" style="width: 100%;" placeholder="请输入" />
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="record()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>
		<!-- 法律报告 -->
		<div class="tc_box report_box" style="width: 400px">
			<p class="tc_title">法律报告</p>
			<div class="tc_txt_box">
				<p class="tc_txt">法律报告类型：</p>
				<select class="dd_list" name="report_list" style="width: 50%;">
					<option value="请选择" selected="selected">--请选择类型--</option>
					<option value="劳动关系纠纷">劳动关系纠纷</option>
					<option value="劳动工伤纠纷">劳动工伤纠纷</option>
					<option value="劳动工亡纠纷">劳动工亡纠纷</option>
					<option value="其他纠纷">其他纠纷</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">基本诉求：</p>
				<input type="text" name="report_appeal" placeholder="请输入基本诉求" style="width: 50%; text-indent: .5em;"/>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">在公司工作时长(月)：</p>
				<input type="text" name="report_workTime" placeholder="请输入工作时长" style="width: 50%; text-indent: .5em;" oninput="value=value.replace(/[^\d]/g,'')" />
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">公司拖欠工资时长(月)：</p>
				<input type="text" name="report_owedTime" placeholder="请输入拖欠工资时长" style="width: 50%; text-indent: .5em;" oninput="value=value.replace(/[^\d]/g,'')" />
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">月工资金额：</p>
				<input type="text" name="report_money" placeholder="请输入工资金额" style="width: 50%; text-indent: .5em;" oninput="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" />
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">是否签订劳动合同：</p>
				<select class="dd_list" name="report_contract" style="width: 50%;">
					<option value="已签订" selected="selected">已签订</option>
					<option value="未签订">未签订</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">是否还在职：</p>
				<select class="dd_list" name="report_position" style="width: 50%;">
					<option value="在职" selected="selected">在职</option>
					<option value="已离职">已离职</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">是否缴纳社保：</p>
				<select class="dd_list" name="report_social" style="width: 50%;">
					<option value="已缴纳" selected="selected">已缴纳</option>
					<option value="未缴纳">未缴纳</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">是否有加班情况：</p>
				<select class="dd_list" name="report_overtime" style="width: 50%;">
					<option value="有加班情况" selected="selected">有加班情况</option>
					<option value="无加班情况">无加班情况</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">伤残等级：</p>
				<input type="text" name="report_disability" placeholder="请输入伤残等级(数字)" style="width: 50%; text-indent: .5em;"
				 oninput="value=value.replace(/[^\d]/g,'')" maxlength="2"/>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">医疗费用：</p>
				<input type="text" name="report_health" placeholder="请输入医疗费用(数字)" style="width: 50%; text-indent: .5em;" oninput="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" />
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">辅助器械费：</p>
				<input type="text" name="report_auxiliary" placeholder="请输入费用(数字)" style="width: 50%; text-indent: .5em;" oninput="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" />
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">是否解除劳动关系：</p>
				<select class="dd_list" name="report_relations" style="width: 50%;">
					<option value="已解除劳动关系" selected="selected">已解除劳动关系</option>
					<option value="未解除劳动关系">未解除劳动关系</option>
				</select>
			</div>
			<div class="tc_txt_box">
				<p class="tc_txt">一次性工亡补助金：</p>
				<input type="text" name="report_death" placeholder="请输入金额(数字)" style="width: 50%; text-indent: .5em;" oninput="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''" />
			</div>
			<p class="tc_txt">律师建议：</p>
			<div class="tc_txt_box">
				<textarea rows="3" name="report_proposal"></textarea>
			</div>
			<div class="tc_btn_box">
				<button class="btn btn-success" onclick="report()">确认</button>
				<button class="btn btn-warning" onclick="closeshow()">取消</button>
			</div>
		</div>

	</div>
	<!-- 提示 -->
	<script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
	<script src="__STATIC__/js/admin.js"></script>
	<script>
		$("input").attr("autocomplete","off");
		// 新用户弹窗
		function show_name() {
			show('.user_box');
		}
		// 订单弹窗
		function show_order(uid) {
			show('.order_box', uid);
		}
		// 丢入公海
		function show_discard(uid) {
			show('.discard_box', uid);
		}
		// 重新指派
		function show_raload(uid) {
			show('.reload_box', uid);
		}
		// 约访
		function show_record(uid) {
			show('.record_box', uid);
		}
		// 法律报告
		function show_report(uid) {
			show('.report_box', uid);
		}
		//  弹窗
		function show(name, uid) {
			var userid = uid || "";
			$(".tc_bg").css("display", "block");
			$("input[type = 'hidden']", ".tc_box").remove();
			$(name).append('<input type="hidden" value="' + userid + '">');
			$(name).css("display", "block");
		}
		//  关闭
		function closeshow() {
			$(".tc_box").css("display", "none");
			$(".tc_bg").css("display", "none");
		}
		// 用户验证
		function phone() {
			$("button").attr("disabled",true);
			var val = $("input[name = 'phone']", ".tc_box").val();
			if ((/^1[3456789]\d{9}$/.test(val))) {
				$.ajax({
					type: "post",
					url: "{:url('user/admin_index/add_user')}",
					data: {
						phone: val
					},
					dataType: "json",
					success: function(data) {
						if (data.code == 1) {
							ts(data.msg);
							setTimeout(function() {
								location.reload();
							}, 1800);
						} else {
							ts(data.msg);
						}
					},
					error: function(data) {
						ts("发生未知错误，请刷新页面后重试！");
						setTimeout(function() {
							location.reload();
						}, 1800);
					}
				});
			} else if (val == "") {
				ts("请输入手机号码！");
				$("input[name = 'phone']", ".tc_box").css("border-color", "red");
			} else {
				ts("请检查您输入的手机号码！");
				$("input[name = 'phone']", ".tc_box").css("border-color", "red");
			}
		}
		// 订单验证
		function order() {
			$("button").attr("disabled",true);
			var sel = $("select[name = 'order']", ".tc_box").val();
			var money = $("input[name = 'money']", ".tc_box").val();
			var arr = $("input[type = 'hidden']", ".tc_box").val().split(",");
			var uid = arr[0];
			var about = arr[1];
			if (money != "") {
				$.ajax({
					type: "post",
					url: "{:url('user/admin_index/add_order')}",
					data: {
						user_id: uid,
						money,
						order_type: sel,
						about
					},
					dataType: "json",
					success: function(data) {
						if (data.code == 1) {
							ts(data.msg);
							setTimeout(function() {
								location.reload();
							}, 1800);
						} else {
							ts(data.msg);
						}
					},
					error: function(data) {
						ts("发生未知错误，请刷新页面后重试！");
						setTimeout(function() {
							location.reload();
						}, 1800);
					}
				});
			} else {
				ts("请输入金额！");
				$("input[name = 'money']", ".tc_box").css("border-color", "red");
			}
		}
		// 丢入公海验证
		function discard() {
			$("button").attr("disabled",true);
			var val = $("input[name = 'why']", ".tc_box").val();
			var uid = $("input[type = 'hidden']", ".tc_box").val();
			if (val != "") {
				$.ajax({
					type: "post",
					url: "{:url('user/admin_index/throw_waters')}",
					data: {
						user_id: uid,
						feedback: val
					},
					dataType: "json",
					success: function(data) {
						if (data.code == 1) {
							ts(data.msg);
							setTimeout(function() {
								location.reload();
							}, 1800);
						} else {
							ts(data.msg);
						}
					},
					error: function(data) {
						ts("发生未知错误，请刷新页面后重试！");
						setTimeout(function() {
							location.reload();
						}, 1800);
					}
				});
			} else {
				ts("请输入原因！");
				$("input[name = 'why']", ".tc_box").css("border-color", "red");
			}
		}
		// 重新指派验证
		function raload() {
			$("button").attr("disabled",true);
			var val = $("input[name = 'people']", ".tc_box").val();
			var uid = $("input[type = 'hidden']", ".tc_box").val();
			if (val != "" && (/^([\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}|[a-zA-Z][a-zA-Z\.\s]{1,19})$/.test(val))) {
				$.ajax({
					type: "post",
					url: "{:url('user/admin_index/appointees')}",
					data: {
						user_id: uid,
						about_name: val
					},
					dataType: "json",
					success: function(data) {
						if (data.code == 1) {
							ts(data.msg);
							setTimeout(function() {
								location.reload();
							}, 1800);
						} else {
							ts(data.msg);
						}
					},
					error: function(data) {
						ts("发生未知错误，请刷新页面后重试！");
						setTimeout(function() {
							location.reload();
						}, 1800);
					}
				});
			} else if (val == "") {
				ts("请指派约访人！");
				$("input[name = 'people']", ".tc_box").css("border-color", "red");
			} else {
				ts("请检查指派人员格式！");
				$("input[name = 'people']", ".tc_box").css("border-color", "red");
			}
		}
		// 约访记录验证
		function record() {
			$("button").attr("disabled",true);
			var uid = $("input[type = 'hidden']", ".tc_box").val();
			var record_list = $("select[name = 'record_list']", ".tc_box").val();
			var record_time = $("input[name = 'record_time']", ".tc_box").val();
			var record_txt = $("input[name = 'record_txt']", ".tc_box").val();
			if (record_list != '请选择' && record_time != "" && record_txt != "") {
				$.ajax({
					type: "post",
					url: "{:url('user/admin_index/appointed')}",
					data: {
						user_id: uid,
						visit_type: record_list,
						time: record_time,
						feedback: record_txt
					},
					dataType: "json",
					success: function(data) {
						if (data.code == 1) {
							ts(data.msg);
							setTimeout(function() {
								location.reload();
							}, 1800);
						} else {
							ts(data.msg);
						}
					},
					error: function(data) {
						ts("发生未知错误，请刷新页面后重试！");
						setTimeout(function() {
							location.reload();
						}, 1800);
					}
				});
			} else if (record_list == '请选择') {
				ts("请选择约访形式！");
			} else if (record_time == "") {
				ts("请填写约访时间！");
			} else if (record_txt == "") {
				ts("请填写约访记录！");
				$("input[name = 'record_txt']", ".tc_box").css("border-color", "red");
			}


			console.log(record_list, record_time, record_txt)
		}
		// 法律报告验证
		function report() {
			// 用户id
			var uid = $("input[type = 'hidden']", ".tc_box").val();
			// 法律报告类型
			var list = $("select[name = 'report_list']", ".tc_box").val();
			// 基本诉求
			var appeal = $("input[name = 'report_appeal']", ".tc_box").val();
			// 在公司工作时长
			var workTime = $("input[name = 'report_workTime']", ".tc_box").val();
			// 公司拖欠工资时长
			var owedTime = $("input[name = 'report_owedTime']", ".tc_box").val();
			// 月工资金额
			var money = $("input[name = 'report_money']", ".tc_box").val();
			// 是否签订劳动合同
			var contract = $("select[name = 'report_contract']", ".tc_box").val();
			// 是否还在职
			var position = $("select[name = 'report_position']", ".tc_box").val();
			// 是否缴纳社保
			var social = $("select[name = 'report_social']", ".tc_box").val();
			// 是否有加班情况
			var overtime = $("select[name = 'report_overtime']", ".tc_box").val();
			// 伤残等级
			var disability = $("input[name = 'report_disability']", ".tc_box").val();
			// 医疗费用
			var health = $("input[name = 'report_health']", ".tc_box").val();
			// 辅助器械费
			var auxiliary = $("input[name = 'report_auxiliary']", ".tc_box").val();
			// 是否解除劳动关系
			var relations = $("select[name = 'report_relations']", ".tc_box").val();
			// 一次性工亡补助金
			var death = $("input[name = 'report_death']", ".tc_box").val();
			// 律师建议
			var proposal = $("textarea[name = 'report_proposal']", ".tc_box").val();
			
			if (list == "请选择") {
				layer.msg("请选择报告类型");
			} else {
				if (appeal == "") {
					layer.msg("请输入基本诉求");
				} else {
					if (list == "劳动关系纠纷") {
						if (workTime == "") {
							layer.msg("请填写工作时长");
						} else if(money == "") {
							layer.msg("请填写月工资金额");
						} else {
							
						}
					} else if (list == "劳动工伤纠纷") {
						if(money == "") {
							layer.msg("请填写月工资金额");
						} else if (disability == "") {
							layer.msg("请填写伤残等级");
						} else {
							
						}
					} else if (list == "劳动工亡纠纷") {
						if (death == "") {
							layer.msg("请填写一次性工亡补助金");
						} else {
							
						}
					} else {
						
					}
					
					
					
					console.log(uid, list, appeal,workTime, owedTime, money, position, social, overtime, disability, health, auxiliary,
						relations, death, proposal)
				}
			}	
		}
		// 捡起
		function pick(uid) {
			$("button").attr("disabled",true);
			$.ajax({
				type: "post",
				url: "{:url('user/admin_index/pick_up')}",
				data: {
					user_id: uid,
				},
				dataType: "json",
				success: function(data) {
					if (data.code == 1) {
						ts(data.msg);
						setTimeout(function() {
							location.reload();
						}, 1800);
					} else {
						ts(data.msg);
					}
				},
				error: function(data) {
					ts("发生未知错误，请刷新页面后重试！");
					setTimeout(function() {
						location.reload();
					}, 1800);
				}
			});
		}
		// 重置颜色
		$("input", ".tc_box").keydown(function() {
			$(this).css("border-color", "#666666");
		})
		// 提示
		function ts(val) {
			layer.msg(val,{time: 1600});
			$("button").attr("disabled",false);
		}
	</script>

</body>

</html>
